package com.smartremote.sillyagent;

import com.smartremote.sillyagent.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;


public class SillyAgentActivity extends Activity implements OnClickListener {
    //private static final String TAG = SillyAgentActivity.class.getSimpleName();

    private TextView mStatus;
    private Button mStart;
    private Button mStop;
    private Button mCheck;

    public void onClick(View v) {
        if (v == mStop) {
            mStatus.setText("Stopping ...");

            if (doStop()) {
                mStatus.setText("Status: Stopped");
            } else {
                mStatus.setText("Status: Unknown Error");
            }
            return;
        } else if (v == mStart) {
            mStatus.setText("Starting ...");

            if (doStart()) {
                mStatus.setText("Status: Started");
            } else {
                mStatus.setText("Status: Unknown Error");
            }
            return;
        } else if (v == mCheck) {
            mStatus.setText("Checking status ...");
            mStatus.setText("Status: "
                    + (checkStatus() ? "Started" : "Stopped"));
            return;
        }
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        mStatus = (TextView) findViewById(R.id.status);
        mStart = (Button) findViewById(R.id.start);
        mStart.setOnClickListener(this);
        mStop = (Button) findViewById(R.id.stop);
        mStop.setOnClickListener(this);
        mCheck = (Button) findViewById(R.id.check);
        mCheck.setOnClickListener(this);
    }

    private boolean doStart() {
        ScreenUtil screenUtil = new ScreenUtil(this);
        byte[] pngData = screenUtil.screenCaptureToPNG();
        if (pngData != null) {
            FileUtil.writeBytesToFile(pngData, "temp.png");
        }

        return true;
    }

    private boolean doStop() {
        // MotorolaSettings.putInt(getContentResolver(), MotorolaSettings.VIEWSERVER_IN_SECUREBUILD_ENABLED, 0);

        return true;
    }

    private boolean checkStatus() {

        return false;
    }
}
